home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
MOVE.C
< prev
next >
Wrap
Text File
|
1985-04-10
|
1KB
|
54 lines
/*
* Program to move a file from one area to another.
*/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
int c,
filesrc,
filetgt;
if (argc < 2)
{
printf("\n*** Missing Source Filename ***\n");
exit(1);
}
if (argc < 3)
{
printf("\n*** Missing Target Filename ***\n");
printf("Cannot move source to source\n");
exit(2);
}
printf("\nMoving %s to %s\n",argv[1],argv[2]);
if ((filesrc = open(argv[1],0)) == -1)
{
printf("\n*** Cannot open %s ***",argv[1]);
exit(3);
}
if ((filetgt = open(argv[2],0)) != -1)
{
printf("\n*** File %s currently exists ***\n",argv[2]);
printf("\nDo you wish to proceed? ");
c = getchar();
printf("\n");
if ((c != 'y') && (c != 'Y'))
exit(4);
fclose(filetgt);
}
filetgt = creat(argv[2]);
while ((c = fgetc(filesrc)) != EOF)
fputc(c,filetgt);
if ((c = fclose(filetgt)) == -1)
{
printf("\n*** Cannot close target file %s ***\n",argv[2]);
exit(5);
}
if ((c = unlink(argv[1])) == -1)
{
printf("\n*** Cannot delete source file %s ***\n",argv[1]);
exit(6);
}
printf("\nFile %s moved to %s\n",argv[1],argv[2]);
}